package ynu.sxp.demoapp.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import ynu.sxp.demoapp.entity.DeliveryAddress;
import ynu.sxp.demoapp.repository.DeliveryAddressRepository;
import ynu.sxp.demoapp.service.DeliveryAddressService;

import java.util.List;
import java.util.UUID;

@Service
public class DeliveryAddressServiceImpl implements DeliveryAddressService {
    private final DeliveryAddressRepository deliveryAddressRepository;

    @Autowired
    public DeliveryAddressServiceImpl(DeliveryAddressRepository deliveryAddressRepository) {
        this.deliveryAddressRepository = deliveryAddressRepository;
    }

    @Override
    public DeliveryAddress createDeliveryAddress(DeliveryAddress deliveryAddress) {
        return deliveryAddressRepository.save(deliveryAddress);
    }

    @Override
    public DeliveryAddress getDeliveryAddressById(UUID daId) {
        return deliveryAddressRepository.findById(daId).orElse(null);
    }

    @Override
    public List<DeliveryAddress> getDeliveryAddressesByUserId(String userId) {
        return deliveryAddressRepository.findByUserId(userId);
    }

    @Override
    public void updateDeliveryAddress(DeliveryAddress deliveryAddress) {
        deliveryAddressRepository.save(deliveryAddress);
    }

    @Override
    public void deleteDeliveryAddress(UUID daId) {
        deliveryAddressRepository.deleteById(daId);
    }
}